package com.woniu.crm.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.system.service.ISysCodeRulesService;
import com.woniu.crm.domain.CrmCustomer;
import com.woniu.crm.mapper.CrmCustomerMapper;
import com.woniu.crm.service.ICrmCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户信息Service业务层处理
 * 
 * @author woniu
 * @date 2020-06-29
 */
@Service
public class CrmCustomerServiceImpl implements ICrmCustomerService 
{
    @Autowired
    private CrmCustomerMapper crmCustomerMapper;
    @Autowired
    private ISysCodeRulesService sysCodeRulesService;

    /**
     * 查询客户信息
     * 
     * @param id 客户信息ID
     * @return 客户信息
     */
    @Override
    public CrmCustomer selectCrmCustomerById(Long id)
    {
        return crmCustomerMapper.selectCrmCustomerById(id);
    }

    /**
     * 查询客户信息列表
     * 
     * @param crmCustomer 客户信息
     * @return 客户信息
     */
    @Override
    public List<CrmCustomer> selectCrmCustomerList(CrmCustomer crmCustomer)
    {
        return crmCustomerMapper.selectCrmCustomerList(crmCustomer);
    }

    /**
     * 新增客户信息
     * 
     * @param crmCustomer 客户信息
     * @return 结果
     */
    @Override
    public int insertCrmCustomer(CrmCustomer crmCustomer)
    {
        long curcompany = SecurityUtils.getUserCompanyId();
        crmCustomer.setCreateTime(DateUtils.getNowDate());
        crmCustomer.setCompanyId(curcompany);
        crmCustomer.setCreateBy(SecurityUtils.getUserID()+"");
        String code = sysCodeRulesService.selectRulesByCode("CRM_CUS",curcompany+"");
        crmCustomer.setSn(sysCodeRulesService.selectRulesByCode("CRM_CUS",curcompany+""));
        return crmCustomerMapper.insertCrmCustomer(crmCustomer);
    }

    /**
     * 修改客户信息
     * 
     * @param crmCustomer 客户信息
     * @return 结果
     */
    @Override
    public int updateCrmCustomer(CrmCustomer crmCustomer)
    {
        crmCustomer.setUpdateTime(DateUtils.getNowDate());
        crmCustomer.setUpdateBy(SecurityUtils.getUserID()+"");
        return crmCustomerMapper.updateCrmCustomer(crmCustomer);
    }

    /**
     * 批量删除客户信息
     * 
     * @param ids 需要删除的客户信息ID
     * @return 结果
     */
    @Override
    public int deleteCrmCustomerByIds(Long[] ids)
    {
        return crmCustomerMapper.deleteCrmCustomerByIds(ids);
    }

    /**
     * 删除客户信息信息
     * 
     * @param id 客户信息ID
     * @return 结果
     */
    @Override
    public int deleteCrmCustomerById(Long id)
    {
        return crmCustomerMapper.deleteCrmCustomerById(id);
    }
}
